package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.dto.admin.product.evaluate.TempItemDTO;
import com.chushouya.product.dto.admin.product.evaluate.TempEvaluateItemValueEditDTO;
import com.chushouya.product.dto.admin.product.evaluate.TempEvaluateItemAddSingleDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateItemValueDetailDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateItemValueListDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateItemValueQuery;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateItemValueSaveDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateItemValueUpdateDTO;
import com.chushouya.product.service.admin.TempEvaluateItemValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "模板估价项目选项管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/tempEvaluateItemValue")
public class TempEvaluateItemValueController {

    @Resource
    private TempEvaluateItemValueService tempEvaluateItemValueService;

    @ApiOperation("获取模板估价项目选项分页列表")
    @GetMapping("/page")
    public Response<PageResult<TempEvaluateItemValueListDTO>> page(TempEvaluateItemValueQuery query) {
        return Response.success(tempEvaluateItemValueService.selectTempEvaluateItemValuePageResult(query));
    }

    @ApiOperation("获取模板估价项目选项列表")
    @GetMapping("/list")
    public Response<List<TempEvaluateItemValueListDTO>> list(TempEvaluateItemValueQuery query) {
        return Response.success(tempEvaluateItemValueService.selectTempEvaluateItemValueList(query));
    }

    @ApiOperation("根据ID获取模板估价项目选项详细信息")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempItemValueId", value = "模板估价项目选项ID", required = true),
    })
    public Response<TempEvaluateItemValueDetailDTO> getDetail(Long tempItemValueId) {
        return Response.success(tempEvaluateItemValueService.getTempEvaluateItemValueDetail(tempItemValueId));
    }

    @ApiOperation("新增模板估价项目选项")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @RepeatSubmit
    public Response<Long> save(@Validated @RequestBody TempEvaluateItemValueSaveDTO tempEvaluateItemValue) {
        return Response.success(tempEvaluateItemValueService.addTempEvaluateItemValue(tempEvaluateItemValue));
    }

    @ApiOperation("修改模板估价项目选项")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Long> edit(@Validated @RequestBody TempEvaluateItemValueUpdateDTO tempEvaluateItemValue) {
        return Response.success(tempEvaluateItemValueService.editTempEvaluateItemValue(tempEvaluateItemValue));
    }

    @ApiOperation("删除模板估价项目选项")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempItemValueId", value = "模板估价项目选项ID", required = true)
    })
    public Response<Void> remove(Long tempItemValueId) {
        tempEvaluateItemValueService.removeTempEvaluateItemValue(tempItemValueId);
        return Response.success();
    }

    @ApiOperation("根据模板估价项目ID获取选项列表")
    @GetMapping("/listByTempItemId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempItemId", value = "模板估价项目ID", required = true)
    })
    public Response<List<TempEvaluateItemValueListDTO>> listByTempItemId(Long tempItemId) {
        return Response.success(tempEvaluateItemValueService.selectTempEvaluateItemValueListByTempItemId(tempItemId));
    }

    @ApiOperation("根据估价项目选项ID获取模板估价项目选项列表")
    @GetMapping("/listByValueId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "估价项目选项ID", required = true)
    })
    public Response<List<TempEvaluateItemValueListDTO>> listByValueId(Long valueId) {
        return Response.success(tempEvaluateItemValueService.selectTempEvaluateItemValueListByValueId(valueId));
    }

    @ApiOperation("根据模板ID获取模板估价项目组合列表")
    @GetMapping("/combineList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempId", value = "模板ID", required = true)
    })
    public Response<List<TempItemDTO>> combineList(Long tempId) {
        return Response.success(tempEvaluateItemValueService.getTempItemsByTempId(tempId));
    }

    @ApiOperation("修改模板估价项目选项价格")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/updatePrice")
    @RepeatSubmit
    public Response<Boolean> updatePrice(@Validated @RequestBody TempEvaluateItemValueEditDTO editDTO) {
        return Response.success(tempEvaluateItemValueService.updateTempEvaluateItemValuePrice(editDTO));
    }

    @ApiOperation("根据tempItemId和tempId删除整个模板估价项目")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/deleteByTempItemId")
    @RepeatSubmit
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempItemId", value = "模板估价项目ID", required = true),
            @ApiImplicitParam(name = "tempId", value = "模板ID", required = true)
    })
    public Response<Boolean> deleteByTempItemId(@RequestParam Long tempItemId, @RequestParam Long tempId) {
        return Response.success(tempEvaluateItemValueService.deleteTempEvaluateItemByTempItemId(tempItemId, tempId));
    }

    @ApiOperation("根据tempItemValueId删除对应的模板估价记录")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/deleteById")
    @RepeatSubmit
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempItemValueId", value = "模板估价项目选项ID", required = true)
    })
    public Response<Boolean> deleteById(@RequestParam Long tempItemValueId) {
        return Response.success(tempEvaluateItemValueService.deleteTempEvaluateItemValueById(tempItemValueId));
    }

    @ApiOperation("根据估价项目选项ID添加单个模板估价项目")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/addSingle")
    @RepeatSubmit
    public Response<Boolean> addSingle(@Validated @RequestBody TempEvaluateItemAddSingleDTO addSingleDTO) {
        return Response.success(tempEvaluateItemValueService.addTempEvaluateItemSingle(addSingleDTO));
    }
}
